package com.lych.dubbo.api;

import com.lych.model.mongo.Questions;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.ArrayList;
import java.util.List;

@DubboService
public class QuestionsApiImpl implements QuestionsApi{

    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     * 通过问卷id查询试题
     * @param soulIds
     * @return
     */
    @Override
    public List findByIds(List<String> soulIds) {
        List list = new ArrayList();
        for (String soulId : soulIds) {
            Query query = Query.query(Criteria.where("soulId").is(soulId));
            List<Questions> questions = mongoTemplate.find(query, Questions.class);
            list.add(questions);
        }
        return list;
    }
}
